package javafx.com;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class main extends Application {

	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage primaryStage) throws Exception {

		Button button = new Button("button");
		Button button2 = new Button("button2");
		Button button3 = new Button("button3");
		Button button4 = new Button("button3");
		
		AnchorPane anchorPane = new AnchorPane();
		
		anchorPane.setStyle("-fx-background-color:#00BFFF");
		
		HBox hBox = new HBox();
		hBox.setStyle("-fx-background-color:#00FF7F");
		hBox.setPrefHeight(200);
		hBox.setPrefWidth(200);
		
		// 设置内边距
		hBox.setPadding(new Insets(10.0));
		// 设置子组件间距
		hBox.setSpacing(10.0);
		
		// 设置子组件外边距
		hBox.setMargin(button, new Insets(10.0));
		
		// 设置对齐方式
//		hBox.setAlignment(Pos.BOTTOM_CENTER);
		// 设置居中后,上下间距会失效(水平布局) 
		hBox.setAlignment(Pos.CENTER);
		
		// 水平排列,并没有像group和anchorpane一样是覆盖的,当所有组件总长度超过hbox的长度,控件会自动缩小
//		hBox.getChildren().addAll(button,button2,button3,button4);
		hBox.getChildren().addAll(button,button2);
		
		anchorPane.getChildren().add(hBox);
		
		Scene scene = new Scene(anchorPane);
		primaryStage.setScene(scene);
		primaryStage.setTitle("javafx");
		primaryStage.setWidth(600);
		primaryStage.setHeight(600);
		primaryStage.show();
		
	}

}
